<style scoped>
  .weui-form-preview__hd label, .weui-form-preview__hd em {
    font-size: .9em !important;
  }
  .weui-loadmore_line .weui-loadmore__tips {
    background-color: #eee;
  }
  .weui-cells {
    margin-top: 0;
  }
  .weui-cells_form {
    background: #fbfbfb;
  }
  .weui-cell {
    background: #fff;
  }
  .weui-cells__title {
    text-align: left;
  }
  .oitem {
    padding: 3px;
  }
  .hide {
    display: none;
  }
  #acts {
    font-size: 0;
  }
  #acts span {
    font-size: 14px;
  }
  .halfbtn {
    display: inline-block;
    width: 49%;
  }
  .weui-label {
    text-align: left;
  }
  .weui_cell {
    padding: 10px 15px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
    background: #fff;
  }
  .weui-cell_select {
    padding: 0 15px;
  }


  .weui-panel {
    background: #eee;
  }

  .rj-cont-tit {
    margin: 0;
    border-radius: 0;
  }

  .weui-panel {
    margin-top: 0;
    text-align: left;
  }

  .hd .weui-grid.js_grid {
    font-weight: 600;
  }

  .weui-grid.js_grid {
    width: 25%;
    padding: 10px 1px;
  }

  /*.weui-grid.fir {*/
  /*  width: 20%;*/
  /*}*/
  /*.weui-grid.sec {*/
  /*  width: 15%;*/
  /*}*/
  /*.weui-grid.thr {*/
  /*  width: 20%;*/
  /*}*/
  /*.weui-grid.fou {*/
  /*  width: 15%;*/
  /*}*/
  /*.weui-grid.fiv {*/
  /*  width: 15%;*/
  /*}*/
  .weui-grid__label {
    text-overflow: initial;
  }
  .section {
    margin: 5px;
    border-radius: 5px;
  }


  .weui_uploader_input_wrp {
    float: left;
    position: relative;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 77px;
    height: 77px;
    border: 1px solid #D9D9D9;
  }

  .weui_uploader_hd {
    padding-top: 0;
    padding-right: 0;
    padding-left: 0;
  }

  .weui_uploader_files {
    list-style: none;
  }

  .weui_uploader_input_wrp:before {
    width: 2px;
    height: 39.5px;
  }

  .weui_uploader_input_wrp:before, .weui_uploader_input_wrp:after {
    content: " ";
    position: absolute;
    top: 50%;
    left: 50%;
    -webkit-transform: translate(-50%, -50%);
    transform: translate(-50%, -50%);
    background-color: #D9D9D9;
  }

  .weui_uploader_input {
    position: absolute;
    z-index: 1;
    top: 0;
    left: 0;
    width: 100%;
    height: 100%;
    opacity: 0;
    -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  }

  .weui_uploader_input_wrp:after {
    width: 39.5px;
    height: 2px;
  }

  .weui_uploader_bd {
    overflow: hidden;
  }

  .weui_cell {
    padding: 10px 15px;
    position: relative;
    display: -webkit-box;
    display: -webkit-flex;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -webkit-align-items: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .outstore >>> .weui-uploader_files {
    list-style: none;
    overflow-y: hidden;
  }

  .outstore >>> .weui-uploader_file {
    float: left;
    margin-right: 9px;
    margin-bottom: 9px;
    width: 79px;
    background: no-repeat 50%;
    background-size: cover;
  }

  .weui-cell.fir {
    border-top: 0;
  }

  .help {
    text-align: right;
    padding: 5px;
    font-size: 12px;
    color: #bbb;
  }

  .weui_uploader_input_wrp.inrow {
    width: 30px;
    height: 30px;
    margin: 0;
  }

  .weui_uploader_input_wrp:before {
    height: 19.5px;
  }

  .weui_uploader_input_wrp:after {
    width: 19.5px;
  }

  .weui-uploader_file.inrow {
    margin: 0;
    width: 40px;
  }

  li.weui-uploader_file {
    display: inline-block;
    padding: 3px 5px;
  }

  ul#images {
    text-align: right;
  }
  .weui-panel__bd {
    width: auto !important;
    padding: 10px 15px;
    text-align: left;
  }
  .rj-cell {
    font-size: 0.9em;
    display: inline-block;
    margin-right: 15px;
  }

  .weui-navbar a {
    text-decoration: none;
    color: #333;
  }

  .weui_tab_bd_item {
    display: none;
    height: 100%;
    overflow: auto;
  }
  .weui_tab_bd_item.weui_tab_bd_item_active {
    display: block;
  }
</style>
<template>
  <div class="examine" style="background: #eee; padding-bottom: 70px;">
    <div class="rj-wrap" style="background: #fff;">
      {{title}}
      <a href="javascript:;" @click="$router.back(-1)" style="position: absolute; left: 10px; top: 8px">
        <img src="@/assets/back.png" style="width: 20px" />
      </a>
    </div>
    <div class="weui-tab">
      <div class="weui-navbar">
        <a class="weui-navbar__item" href="#tab1">订单信息</a>
        <a class="weui-navbar__item weui-bar__item_on" href="#tab2">调度信息</a>
      </div>
      <div class="weui-tab__panel" style="">
        <div id="tab1" class="weui_tab_bd_item">
          <div class="weui-form-preview section" style="background: #fff;">
            <div class="weui-form-preview__hd">
              <label class="weui-form-preview__label">编号</label>
              <em class="weui-form-preview__value">{{baseInfo.sellcode}}</em>
            </div>
            <div class="weui-form-preview__bd">
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">申请人</label>
                <span class="weui-form-preview__value">{{baseInfo.applyname}} {{baseInfo.depname}}</span>
              </div>
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">销售组织</label>
                <span class="weui-form-preview__value">{{baseInfo.orgName}}</span>
              </div>
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">客户</label>
                <span class="weui-form-preview__value">{{baseInfo.customername}}</span>
                <span v-if="customer != null">{{baseInfo.typename}}</span>
              </div>
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">货品类型</label>
                <span class="weui-form-preview__value">{{baseInfo.quitSRTypeName}}</span>
              </div>
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">付款方式</label>
                <span class="weui-form-preview__value">{{baseInfo.paytypename}}</span>
              </div>
              <div class="weui-form-preview__item" v-if="flowid == 36 && baseInfo.faretypename">
                <label class="weui-form-preview__label">物流结算</label>
                <span class="weui-form-preview__value">{{baseInfo.faretypename}}</span>
              </div>
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">配送方式</label>
                <span class="weui-form-preview__value">{{baseInfo.deliverytypename}}</span>
              </div>
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">要求发货日期</label>
                <span class="weui-form-preview__value">{{baseInfo.senddate}}</span>
              </div>
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">要求到货日期</label>
                <span class="weui-form-preview__value">{{baseInfo.arrivedate}}</span>
              </div>
<!--              <div class="weui-form-preview__item" v-if="baseInfo.settletype == 1">-->
<!--                <label class="weui-form-preview__label">订单件数</label>-->
<!--                <span class="weui-form-preview__value">{{baseInfo.orderpack}}</span>-->
<!--              </div>-->
<!--              <div class="weui-form-preview__item" v-if="baseInfo.settletype == 1 && baseInfo.handselcount">-->
<!--                <label class="weui-form-preview__label">赠送件数</label>-->
<!--                <span class="weui-form-preview__value">{{baseInfo.handselcount}}</span>-->
<!--              </div>-->
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">订单重量</label>
                <span class="weui-form-preview__value">{{baseInfo.weight}} 吨</span>
              </div>
<!--              <div class="weui-form-preview__item" v-if="baseInfo.handselweight">-->
<!--                <label class="weui-form-preview__label">赠送重量</label>-->
<!--                <span class="weui-form-preview__value">{{baseInfo.handselweight}} 吨</span>-->
<!--              </div>-->
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">结算币种</label>
                <span class="weui-form-preview__value">{{baseInfo.currencyName}}</span>
              </div>
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">状态</label>
                <span class="weui-form-preview__value">{{baseInfo.statusname}}</span>
              </div>
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">备注</label>
                <span class="weui-form-preview__value">{{baseInfo.remarks}}</span>
              </div>
              <div class="weui-form-preview__item">
                <label class="weui-form-preview__label">创建时间</label>
                <span class="weui-form-preview__value">{{baseInfo.createtime}}</span>
              </div>
            </div>
          </div>
        </div>
        <div id="tab2" class="weui_tab_bd_item weui_tab_bd_item_active">
          <div class="weui-form-preview section" style="background: #fff;">
            <div class="weui-cells weui-cells_form">
              <div class="weui-cell fir">
                <div class="weui-cell__hd"><label class="weui-label">库存组织</label></div>
                <div class="weui-cell__bd">
                  <select class="weui-select rj-line-select" name="" v-model="org" @change="(e) => {model.storeOrgId = org.id;model.storeOrgName=org.name;}">
                    <option value="" disabled>请选择</option>
                    <option v-for="(item, index) in orgs" :value="item">
                      {{item.name}}
                    </option>
                  </select>
                </div>
              </div>
              <div class="weui-cell">
                <div class="weui-cell__hd"><label class="weui-label">出库库房</label></div>
                <div class="weui-cell__bd">
                  <select class="weui-select" v-model="stroom" @change="takeStrm">
                    <option value="" disabled>请选择</option>
                    <option v-for="(item, index) in storerooms" :key="item.guid" :value="item">
                      {{item.name}}
                    </option>
                  </select>
                </div>
              </div>
              <div class="weui-cell">
                <div class="weui-cell__hd">
                  <label id='unqualifiedchkrateDiv' class="weui-label">发货地址</label></div>
                <div class="weui-cell__bd">
                  <input class="weui-input" type="text" id='deliprovince' name="deliprovince" v-model="packCitys" ></div>
              </div>
              <div class="weui-cell">
                <div class="weui-cell__hd">
                  <label class="weui-label">详细地址</label></div>
                <div class="weui-cell__bd">
                  <input class="weui-input" type="text" name="deliaddress" placeholder=" 请输入发货详细地址" v-model="model.deliAddress"></div>
              </div>
              <div class="weui-cell fir">
                <div class="weui-cell__hd">
                  <label class="weui-label">发货联系人</label></div>
                <div class="weui-cell__bd">
                  <input class="weui-input" name="delicontact" v-model="model.deliContact"
                         placeholder=" 请输入发货联系人"></div>
              </div>
              <div class="weui-cell">
                <div class="weui-cell__hd">
                  <label class="weui-label">联系电话</label></div>
                <div class="weui-cell__bd">
                  <input class="weui-input" type="number" name="delicontacttel"
                         v-model="model.deliContactNo" placeholder=" 请输入发货人手机号"></div>
              </div>
            </div>
          </div>
          <div class="weui-form-preview section" style="background: #fff;">
            <div class="weui-cell weui-cell_select">
              <div class="weui-cell__hd"><label class="weui-label">是否继续拆分</label></div>
              <div class="weui-cell__bd">
                <select class="weui-select" v-model="model.settledays">
                  <option value="">请选择</option>
                  <option value="1">直接调度</option>
                  <option value="2">分拆</option>
                  <option value="3">结束主订单</option>
                </select>
              </div>
            </div>
          </div>
          <!--    动态数据-->
          <p style="height: 5px;"></p>
          <div class="weui-cells weui-cells_form section">
            <form action="" method="post" id="formid">
              <div class="weui-cell fir">
                <div class="weui-cell__hd"><label class="weui-label">附件上传</label></div>
                <div class="weui-cell__ft">
                  <div class="weui_uploader_bd">
                    <ul class="weui_uploader_files"></ul>
                    <div class="weui_uploader_input_wrp inrow">
                      <UploadFile3 class="weui_uploader_input" v-on:pushfile="setFile"></UploadFile3>
                    </div>
                  </div>
                </div>
                <ul class="weui-uploader_files" id="images">
                  <li class="weui-uploader_file" v-for="(fil, index) in filenames" @click=delFile(fil,fileids[index])>
                    {{fil}}
                  </li>
                </ul>
              </div>
              <div class="weui-cell">
                <div class="weui-cell__bd">
                  <textarea class="weui-textarea opinion" v-model="opinion" name="opinion" placeholder="请输入意见内容" rows="2"></textarea>
                </div>
              </div>
            </form>
          </div>
        </div>
      </div>
    </div>

    <div id="bmlogs">
      <SalesOperationLogs7 :nodeid="nodeid" :orderid="id" :srguid="baseInfo.srguid" :departid="baseInfo.depguid" :flowid="flowid"></SalesOperationLogs7>
    </div>
      <ApproveBom v-if="isReady" type="sellDispatch" :flowid="flowid" :nodeid="nodeid" :id="id" :srguid="''" :departid="baseInfo.depguid" :model="model" :opinion="opinion" :fileids="fileids" :refuseflag="refuseflag" :annex="annex" passUrl="/prod-api/bill/sellform/dispatch" refuseUrl="/prod-api/bill/sellform/refuse"  :navgateUrl="`/sellform2/SellformList?flowid=${flowid}`" ></ApproveBom>
  </div>
</template>

<script>
  import wx from 'weixin-js-sdk';
  import SalesOperationLogs7 from '@/components/common/SalesOperationLogs7'
  import ApproveBom from '@/components/common/ApproveBom'
  import UploadFile3 from "../common/UploadFile3";

  export default {
  name: 'Dispatch34',
  data () {
    return {
      flowid: 34,
      opinion: '',
      openid: localStorage.openid,
      id: '',
      title: '',
      nodeid: '',
      annex: '',
      baseInfo: {},
      baseItems: '',
      wxParams: {},
      images: {
        serverId: [],
        srcStr: [],
      },
      refuseflag: '',
      refuseNodes: [],
      orderfiles: [],
      isReady: false,
      filenames: [],
      fileids: [],
      qaform:{},
      qaFormImg:[],
      titleName:"",
      whoutform:[],
      whinform:[],
      wlinfo: {}, //物流信息
      orgs: [],
      org: '',
      storerooms: [],
      stroom: '',
      model: {
        settledays: 1
      },
      packCitys: ''
    }
  },
    components: {
      SalesOperationLogs7,
      ApproveBom,
      UploadFile3
    },
    computed: {
      pageTitle: function () {
        let tit = '销售订单';
        switch (this.flowid) {
          case '34':
            tit = '电商订单';
            break;
          case '35':
            tit = '样品订单';
            break;
          default:
            tit = '销售订单';
            break;
        }
        return tit;
      }
    },
    created() {
      if (this.$route.query.flowid) this.flowid = this.$route.query.flowid;
      //页面title设置
      document.title = '土豆集-' + this.pageTitle;
    },
  mounted () {
    $('.weui-navbar__item').on('click', function () {
      $(this).addClass('weui-bar__item_on').siblings('.weui-bar__item_on').removeClass('weui-bar__item_on');
      //内容切换
      $(".weui-tab__panel .weui_tab_bd_item_active").removeClass('weui_tab_bd_item_active');
      var data_toggle = jQuery(this).attr("href");
      $(data_toggle).addClass("weui_tab_bd_item_active");
    });

    //$('#opinion').focus();
    this.id = this.$route.query.id;
    this.nodeid = this.$route.query.nodeid;
    this.annex = this.$route.query.annex;
    this.title = this.$route.query.title;
    this.refuseflag = this.$route.query.refuseflag;
    this.getBaseInfo(this.id);
    this.getOrgs();
    if (this.$route.query.status) {
      this.status = this.$route.query.status;
    }
    $("#deliprovince").cityPicker({
      title: "请选择发货地址",
    });
    let that = this;
    $("#deliprovince").change(function () {
      let addr = $(this).val().split(' ');
      that.model.deliProvince = addr[0];
      that.model.deliCity = addr[1];
      that.model.deliDistrict = addr[2];
    })
    this.model.id = this.id;
  },
  watch: {
    org: function (val) {
      this.getSr(val.guid);
    },
  },
  methods: {
    takeStrm() {
      this.model.storermguid = this.stroom.guid;
      this.model.strmId = this.stroom.id;
      this.model.storeroomname=this.stroom.name;
      this.packCitys = this.stroom.province + ' ' + this.stroom.city + ' ' + this.stroom.area;
      this.model.deliProvince = this.stroom.province;
      this.model.deliCity = this.stroom.city;
      this.model.deliDistrict = this.stroom.area;
      this.model.deliAddress=this.stroom.address;
      this.model.deliContact=this.stroom.contact;
      this.model.deliContactNo=this.stroom.contacttel;
    },
    getOrgs: function() {
      this.axios({
        method: 'get',
        url: '/prod-api/getOrgs',
      }).then(response => {
        if (response.data.code == 200) {
          this.orgs = response.data.data;
        } else {
          this.toastText('获取组织数据失败')
        }
      });
    },
    getSr: function(orgId) {
      this.axios({
        method: 'get',
        url: '/prod-api/getStoreRoomByOrgIdOrPermissions',
        params: {guid: orgId, enable: 1}
      }).then(response => {
        if (response.data.code == 200) {
            this.storerooms = response.data.data;
        } else {
          this.toastText('获取库房数据失败');
        }
      });
    },
    delFile: function (name, id) {
      let that = this;
      $.confirm('确定要删除？', function () {
        that.axios({
          method: 'post',
          url: '/prod-api/common/delete',
          params: {id: id}
        })
        that.fileids = that.fileids.filter(item => {
          return item != id;
        })
        that.filenames = that.filenames.filter(item => {
          return item != name;
        })
      })
    },
    setFile: function (file) {
      this.filenames.push(file.name);
      this.fileids.push(file.id);
    },
    getBaseInfo: function (id) {
      this.axios({
        method: 'get',
        url: `/prod-api/bill/sellform//detail`,
        params: {orderid: id}
      }).then(response => {
        if (response.data.code == 200) {
          let data = response.data.data;
          this.baseInfo = data.result || {};
        } else if (response != undefined && response.data != undefined && response.data.msg == 'sessionTimeOut') {
          //不不设置提示
        } else {
          this.toastError('系统错误');
        }
        this.isReady = true;
      });
    },

}
}
</script>
